package com.seagull.sb.security;


import java.security.Principal;

import javax.ws.rs.core.SecurityContext;
 
public class SBSecurityContext implements javax.ws.rs.core.SecurityContext {
 
    private BaseUser user;
    
    
    
    public SBSecurityContext(BaseUser user) {
        this.setUser(user);
    }
 
    @Override
    public String getAuthenticationScheme() {
        return SecurityContext.BASIC_AUTH;
    }
 
    @Override
    public Principal getUserPrincipal() {
        return getUser();
    }
 
    @Override
    public boolean isSecure() {
        return (null != getUser()) ? true : false;
    }
 
    @Override
    public boolean isUserInRole(String role) {
//    	  return true;
//        if (null == session || !session.isActive()) {
//            // Forbidden
//            Response denied = Response.status(Response.Status.FORBIDDEN).entity("Permission Denied").build();
//            throw new WebApplicationException(denied);
//        }
// 
        try {
            // this user has this role?
            return (getUser().getRole() == UserStudent.Role.valueOf(role));
        } catch (Exception e) {
        	e.printStackTrace();
        }
         
        return false;
    }

	public BaseUser getUser() {
		return user;
	}

	public void setUser(BaseUser user) {
		this.user = user;
	}
}